import Cookies from 'js-cookie'
const app = {
  state: {
    sidebar: {
      opened: !+Cookies.get('sidebarStatus'),
      withoutAnimation: false,
      noDropdown: true,
      hideUeditor: false,
      redirect: null
    },
    inEdition: false,
    is_jurisdiction: Cookies.get('IS_JURISDICTION'),
    independent: Cookies.get('independent'),//主要用于判断是否是独立版和微擎版
    version: Cookies.get('VERSION') || 'user',
    isToLogin: !Cookies.get('_WeliamAdmin') || window.location.hostname === 'localhost',
    newsMessage: Cookies.get('newsMessage') || [],
    breadcrumbTitle: '',
    displayMap: ['/channel/weChatPublicChannel', '/channel/alipayAppletsChannel', '/channel/baiduAppletsChannel', '/channel/toutiaoAppletsChannel', '/channel/h5Channel', '/channel/weChatMenuChannelList', '/channel/weChatReplyChannelList', '/channel/weChatReplyChannelListAdd', '/channel/weChatMenuChannelAdd', '/channel/weChatPublicImageSource', '/channel/weChatPublicVideoSource', '/channel/weChatPublicAudioSource', '/channel/weChatPublicUeditorSource', '/channel/weChatPublicUeditorSourceAdd', '/channel/weChatAppletsChannel', '/channel/weChatAppletsChannelRedirect', '/channel/weChatAppletsChannelPublish'],
    power: Cookies.get('power') || [],
    baseURL: 'https://devwe7.weliam.cn/addons/weliam_areashop/web/index.php?s=',
    device: 'desktop',
    copyright: '',
    sitename: '',
    language: Cookies.get('language') || 'zh',
    size: Cookies.get('size') || 'medium',
    beforepath: Cookies.get('beforepath') || ''
  },
  mutations: {
    SET_VERSION: (state, version) => {
      state.version = version
    },
    SET_INEDITION(state, inEdition) {
      state.inEdition = inEdition
    },
    SET_INDEPENDENT: (state, independent) => {
      state.independent = independent
    },
    TOGGLE_SIDEBAR: state => {
      if (state.sidebar.opened) {
        Cookies.set('sidebarStatus', 0)
      } else {
        Cookies.set('sidebarStatus', 0)
      }
      state.sidebar.opened = !state.sidebar.opened
      state.sidebar.withoutAnimation = false
    },
    TOGGLE_DROPDOWN: (state, noDropdown) => {
      state.sidebar.noDropdown = noDropdown
    },
    CLOSE_SIDEBAR: (state, withoutAnimation) => {
      Cookies.set('sidebarStatus', 0)
      state.sidebar.opened = false
      state.sidebar.withoutAnimation = withoutAnimation
    },
    TOGGLE_DEVICE: (state, device) => {
      state.device = device
    },
    SET_LANGUAGE: (state, language) => {
      state.language = language
      Cookies.set('language', language)
    },
    SET_SIZE: (state, size) => {
      state.size = size
      Cookies.set('size', size)
    },
    SET_NEW_MESSAGE: (state, page) => {
      state.newsMessage = page
      Cookies.set('newsMessage', state.newsMessage)
    },
    SET_BREADCRUMB_TITLE: (state, page) => {
      state.breadcrumbTitle = page
    },
    SET_POWER: (state, power) => {
      state.power = power
      Cookies.set('power', power)
    },
    SET_COPYRIGHT: (state, copyright) => {
      state.copyright = copyright
    },
    SET_SITENAME: (state, sitename) => {
      state.sitename = sitename
    },
    SET_RROUTER_BEFORE: (state, path, meta) => {
      state.beforepath = path
      Cookies.set('beforepath', path)
    },
    SET_REDIRECT: (state, redirect) => {
      state.sidebar.redirect = redirect
    },
    SET_HIDE_UEDITOR: (state, hideUeditor) => {
      state.sidebar.hideUeditor = hideUeditor
    }
  },
  actions: {
    toggleSideBar({ commit }) {
      commit('TOGGLE_SIDEBAR')
    },
    toggleDropdown({ commit }, noDropdown) {
      commit('TOGGLE_DROPDOWN', !!noDropdown)
    },
    closeSideBar({ commit }, { withoutAnimation }) {
      commit('CLOSE_SIDEBAR', withoutAnimation)
    },
    toggleDevice({ commit }, device) {
      commit('TOGGLE_DEVICE', device)
    },
    setLanguage({ commit }, language) {
      commit('SET_LANGUAGE', language)
    },
    setSize({ commit }, size) {
      commit('SET_SIZE', size)
    },
    setNewsMessage({ commit }, page) {
      console.log(page, 'page')
      commit('SET_NEW_MESSAGE', page)
    },
    setbBreadcrumbTitle({ commit }, page) {
      console.log(page, 'page')
      commit('SET_BREADCRUMB_TITLE', page)
    },
    setPower({ commit }, power) {
      commit('SET_POWER', power)
    },
    setCopyright({ commit }, copyright) {
      commit('SET_COPYRIGHT', copyright)
    },
    setSitename({ commit }, sitename) {
      commit('SET_SITENAME', sitename)
    },
    SetRrouterBefore({ commit }, path, meta) {
      commit('SET_RROUTER_BEFORE', path, meta)
    },
    setRedirect({ commit }, redirect) {
      commit('SET_REDIRECT', redirect)
    },
    setHideUeditor({ commit }, hideUeditor) {
      commit('SET_HIDE_UEDITOR', hideUeditor)
    }
  }
}

export default app
